const app = getApp();
import { order } from '../../../../api/mine/cash';

Page({
  data: {
    header: app.global.headerHeight,
    theme: '',
    back: true,
    title: '提现记录',
    loading: true,
    loadmore: false,
    list: null,
    form: {
      page: 1,
      limit: 10,
      status: 0,
    },
    abnor: {
      title: '未搜索到提现记录~',
      button: ''
    }
  },
  onLoad(options) {
    this.setData({ loading: true, theme: app.global.theme })
    this.getList()
  },
  onPullDownRefresh() {/*监听用户下拉动作*/ },
  onReachBottom() {
    if (this.data.form.page == this.data.form.last_page) {
      this.setData({ loadmore: true })
    } else {
      this.data.form.page += 1
      this.getList()
    }
  },

  //===================methon================

  getList(res) {
    order(this.data.form).then(res => {
      const { data } = res
      this.data.list || (this.data.list = [])
      const list = this.data.list.concat(data.data)
      this.data.form.last_page = res.data.last_page
      this.setData({
        list: list,
        init: false,
        loadmore: data.last_page <= 1
      })
    })
      .finally(() => {
        this.setData({ loading: false })
        wx.hideLoading()
      })
  },

  onChange(event) {
    let form = this.data.form
    form.status = event.detail.index;
    form.page = 1
    this.setData({
      list: null,
      form: form
    });
    wx.showLoading({ title: '加载中' });
    this.getList()
  }
})